<?php
/**
 * 	Bushido
 *
 * @category   Bushido
 * @package    Bushido_App
 * @copyright  Copyright (c) 2008-2009 Nathan Keyes
 * @author Nathan Keyes
 * @version    $Id: IpAddress.php 7 2009-11-14 22:42:08Z nkeyes $
 */

/**
 * @see Zend_Session_Validator_Abstract
 */
require_once 'Zend/Session/Validator/Abstract.php';


class Bushido_Session_Validator_IpAddress extends Zend_Session_Validator_Abstract
{

    /**
     * Setup() - this method will get the current ip address and store it in the session
     * as 'valid data'
     *
     * @return void
     */
    public function setup()
    {
        $this->setValidData( (isset($_SERVER['REMOTE_ADDR'])
            ? $_SERVER['REMOTE_ADDR'] : null) );
    }

    /**
     * Validate() - this method will determine if the current ip address matches the
     * user agent we stored when we initialized this variable.
     *
     * @return bool
     */
    public function validate()
    {
        $currentIpAddress = (isset($_SERVER['REMOTE_ADDR'])
            ? $_SERVER['REMOTE_ADDR'] : null);

        return $currentIpAddress === $this->getValidData();
    }

}
